home *** CD-ROM | disk | FTP | other *** search
- ;void input_real(col,row,color,max_left,max_right,return_string);
- ; unsigned short col,row,color,max_left,max_right,;
- ; char *return_string;
-
- EXTRN _memory_model:byte
- EXTRN _beep_on:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _input_real
- _input_real proc near
- push bp ;
- mov bp,sp ;set up stack pointer
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- les si,dword ptr[bp+14] ;get ptr to return string
- jmp short L00 ;
- L0: mov ax,ds ;ES = DS
- mov es,ax ;
- mov si,[bp+14] ;
- L00: mov byte ptr es:[si],0 ;set NumStrg descriptor
- mov dl,[bp+4] ;column in DL
- dec dl ;count from 0
- cmp dl,79 ;in range?
- jna B1 ;jump ahead if not
- A1: jmp L2 ;else quit
- B1: mov dh,[bp+6] ;row in DH
- dec dh ;count from 0
- cmp dh,24 ;in range?
- ja A1 ;quit if so
- mov cx,[bp+12] ;MaxRight to CX
- push CX ;push on to stack
- sub cx,cx ;0 = current rightlen
- push cx ;push on to stack
- sub bh,bh ;select page 0
- mov bl,[bp+8] ;attribute in BL
- mov al,[bp+10] ;MaxLeft to AL
- sub ah,ah ;clear AH
- mov di,ax ;store MaxLeft in DI
- sub bp,bp ;current leftlen in BP
- mov ah,2 ;function to set cursor
- int 10h ;set cursor
- mov ah,9 ;function to write char
- mov al,'.' ;will write decimal point
- mov cx,1 ;number chars to write
- int 10h ;write the decimal point
- mov ah,2 ;function to set cursor
- dec dl ;cursor 1 col to left
- int 10h ;set the cursor
- C1: sub ah,ah ;func to read keystroke
- int 16h ;wait for keystroke
- or al,al ;test for extended code
- jnz D1 ;jump if not extended
- cmp ah,83 ;is it the delete key?
- jne C1 ;next keystroke if not
- jmp L1 ;else jump to delete code
- D1: cmp al,8 ;is it the backspace?
- jne E1 ;jump ahead if not
- jmp L1 ;else go to delete code
- E1: cmp al,13 ;chk for carriage return
- jne F1 ;jump ahead if not
- jmp K2 ;else go to CR code
- F1: cmp al,'.' ;chk for decimal point
- jne G1 ;jump ahead if not
- jmp Q1 ;else go to decimal code
- G1: cmp al,'-' ;chk for minus sign
- jne H1 ;jump ahead if not
- or bp,bp ;current leftlen 0?
- jnz C1 ;new keystroke if not
- inc di ;inc MaxLeft counter
- jmp I1 ;go write it
- H1: cmp al,'0' ;below '0' char?
- jb C1 ;get another keystroke
- cmp al,'9' ;above '9' char?
- ja C1 ;get another keystroke
- cmp bp,di ;cmp leftlen to max
- jb I1 ;jump ahead if not full
- push dx ;keep cursor position
- mov ah,2 ;DOS func to write char
- mov dl,7 ;bell character
- cmp _beep_on,0 ;test if beep enabled
- je H3 ;jump if not
- int 21h ;beep!
- H3: pop dx ;restore cursor position
- jmp short C1 ;go get another keystroke
- I1: inc bp ;inc current leftlen
- cmp bp,1 ;only 1 char?
- je K1 ;no char shift if so
- push ax ;save new keystroke
- mov cx,bp ;current leftlen to CX
- dec cx ;count from 0
- sub dl,cl ;shift curs to lft char+1
- J1: inc dl ;cursor back 1 to right
- mov ah,2 ;func to set cursor
- int 10h ;set the cursor
- mov ah,8 ;func reads cursor char
- int 10h ;read the char
- push ax ;save char
- dec dl ;shift cursor 1 col left
- mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- pop ax ;restore char
- push cx ;keep counter in CX
- mov ah,9 ;function to write char
- mov cx,1 ;number chars to write
- int 10h ;write the char
- pop cx ;restore counter
- inc dl ;cursor right 1 col
- loop J1 ;go shift next
- mov ah,2 ;func to set cursor
- int 10h ;set the cursor
- pop ax ;restore new keystroke
- K1: mov ah,9 ;function to write char
- mov cx,1 ;number chars to write
- int 10h ;write the char in AL
- mov cl,1 ;increment value
- add es:[si],cl ;inc NumStrg descriptor
- mov es:[si][bp],al ;write char to NumStrg
- jmp C1 ;go get next keystroke
- L1: or bp,bp ;DELETE: none to delete?
- jnz M1 ;jump ahead if not
- jmp C1 ;ignor, next keystroke
- M1: push dx ;save cursor position
- dec bp ;dec current leftlen
- push bp ;save current leftlen
- or bp,bp ;test for 0 len
- jnz O1 ;if not 0, shift chars
- mov al,'-' ;1 char, test if '-'
- cmp es:[si+1],al ;chk 1st char in string
- jne N1 ;jump ahead if not '-'
- dec di ;else dec MaxLeft ctr
- N1: jmp P1 ;skip char shift when 0
- O1: dec dl ;move cursor 1 col left
- mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- mov ah,8 ;func reads char at curs
- int 10h ;read the char
- push ax ;save the char
- inc dl ;move cursor 1 col right
- mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- pop ax ;restore the char
- mov ah,9 ;func to write a char
- mov cx,1 ;number chars to write
- int 10h ;write the char
- dec dl ;move cursor 1 col left
- dec bp ;dec str len counter
- cmp bp,0 ;finished shifting chars?
- jne O1 ;loop if not
- mov ah,2 ;func to set cursor
- int 10h ;set the cursor
- P1: mov al,' ' ;write space char
- mov ah,9 ;function to write char
- int 10h ;erase leftmost char
- pop bp ;restore current leftlen
- pop dx ;restore cursor position
- mov ah,2 ;func to set cursor
- int 10h ;set cursor
- mov cl,1 ;decrement value
- sub es:[si],cl ;dec ret str descriptor
- jmp C1 ;go get next keystroke
- Q1: pop ax ;pop (dummy) current len
- pop cx ;pop max rightlen
- push di ;save max leftlen
- push bp ;save current leftlen
- mov di,bp ;current leftlen to DI
- add di,cx ;add max rightlen
- inc bp ;inc current len '.'
- inc di ;inc max len for '.'
- mov cl,1 ;increment for strg len
- add es:[si],cl ;inc NumStrg descriptor
- mov al,'.' ;prepare to write '.'
- mov es:[si][bp],al ;add '.' to NumStrg
- add dl,2 ;cursor 2 cols to right
- mov ah,2 ;func to set cursor
- int 10h ;set the cursor
- sub cx,cx ;clear CX for flags
- R1: sub ah,ah ;func to read keystroke
- int 16h ;wait for a keystroke
- cmp al,0 ;test for extended code
- jnz S1 ;jump if not extended
- cmp ah,83 ;test for delete key
- je A2 ;jump to backspace code
- jmp short R1 ;get another keystroke
- S1: cmp al,13 ;is it a carriage return?
- jne T1 ;jump ahead if not
- jmp K2 ;else quit routine
- T1: cmp al,'e' ;test for 'e'
- jne V1 ;jump ahead if not 'e'
- U1: or cl,cl ;test CL (1 = already e)
- jnz R1 ;discard if CX = 1
- mov cl,1 ;set flag in CL
- jmp short I2 ;go write the char
- V1: cmp al,'E' ;test for 'E'
- jne W1 ;jump ahead if not 'E'
- jmp short U1 ;else go test flag
- W1: cmp al,'+' ;test for '+'
- jne Y1 ;jump if not '+'
- X1: or cl,cl ;test if 'e' written
- jz R1 ;new keystroke if not
- or ch,ch ;test if +/- written
- jnz R1 ;new keystroke if so
- mov ch,1 ;set flag +/- written
- jmp short I2 ;go write the char
- Y1: cmp al,'-' ;test for '-'
- jne Z1 ;jump if not '-'
- jmp short X1 ;go test flags
- Z1: cmp al,8 ;test for backspace
- jne H2 ;jump ahead if not
- A2: mov al,'.' ;seek '.' in NumStrg
- mov ah,es:[si][bp] ;get char in NumStrg
- cmp ah,al ;is it '.'?
- jne B2 ;jump ahead if not
- sub dl,2 ;cursor 2 cols to left
- mov ah,2 ;function to set cursor
- int 10h ;reset cursor
- pop bp ;current leftlen to BP
- pop cx ;max leftlen to CX
- sub di,bp ;calc prior maxleft
- dec di ;minus one for decimal
- push di ;save as max rightlen
- push di ;push dummy value
- mov di,cx ;move max leftlen to DI
- mov al,1 ;number to dec
- sub es:[si],al ;dec descriptor for '.'
- jmp L1 ;switch to left side code
- B2: cmp ah,'+' ;erasing '+'?
- jne C2 ;jump if not
- sub ch,ch ;clear flag
- C2: cmp ah,'-' ;erasing '-'?
- jne D2 ;jump if not
- sub ch,ch ;clear flag
- D2: cmp ah,'e' ;erasing 'e'?
- jne E2 ;jump if not
- sub cl,cl ;clear flag
- E2: cmp ah,'E' ;erasing 'E'?
- jne F2 ;jump if not
- sub cl,cl ;clear flag
- F2: dec dl ;cursor 1 col to left
- mov ah,2 ;function to set cursor
- int 10h ;reset the cursor
- mov al,' ' ;space char for erasure
- mov ah,9 ;function to write char
- push cx ;save flags in CX
- mov cx,1 ;num chars to write
- int 10h ;erase end character
- dec bp ;dec current str len
- sub es:[si],cl ;dec NumStrg descriptor
- pop cx ;restore flags
- G2: jmp R1 ;go get next keystroke
- H2: cmp al,'0' ;test if char < '0'
- jb G2 ;new keystroke if below
- cmp al,'9' ;test if char > '9'
- ja G2 ;new keystroke if above
- I2: cmp di,bp ;compare current/max lens
- jne J2 ;proceed if not equal
- push dx ;else save DX
- mov ah,2 ;DOS func to write char
- mov dl,7 ;bell character to DL
- cmp _beep_on,0 ;test whether beep enabled
- je I3 ;jump ahead if not
- int 21h ;beep!
- I3: pop dx ;restore DX
- jmp R1 ;go get another keystroke
- J2: mov ah,9 ;function to write char
- push cx ;save flags in CX
- mov cx,1 ;number chars to write
- int 10h ;write the character
- add es:[si],cl ;inc NumStrg descriptor
- pop cx ;restore flags in CX
- inc bp ;inc current len ctr
- mov es:[si][bp],al ;write char to NumStrg
- inc dl ;cursor 1 col to right
- mov ah,2 ;function to set cursor
- int 10h ;reset the cursor
- jmp R1 ;go get next keystroke
- K2: pop cx ;balance stack
- pop cx ;
- L2: sub cx,cx ;change to C string
- mov cl,es:[si] ;get string length
- jcxz N2 ;quit if null
- M2: inc si ;
- mov al,es:[si] ;
- mov es:[si-1],al ;
- loop M2 ;
- mov byte ptr es:[si],0 ;null terminator
- N2: pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _input_real ENDP
- _TEXT ENDS
- END